using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using THSLib;using THSERP.BaseProvider;

namespace THSERP.Modules.Processing
{
    public partial class ICProductAttributesTreeListControl : THSTreeListControl
    {
        public override void InitializeControl()
        {
            base.InitializeControl();
            this.CellValueChanging += new DevExpress.XtraTreeList.CellValueChangedEventHandler(TreeList_CellValueChanging);
        }

        public override void InitTreeListColumns(string strTableName)
        {
            base.InitTreeListColumns(strTableName);

            DevExpress.XtraTreeList.Columns.TreeListColumn col1 = InitTreeListColumn(strTableName, -1, "ICInventoryStockQuantity", "On-hand Quantity", 50);
            col1.OptionsColumn.AllowEdit = false;
            DevExpress.XtraTreeList.Columns.TreeListColumn col2 = InitTreeListColumn(strTableName, -1, "ICInventoryStockSaleOrderQuantity", "Customer Order Quantity", 50);
            col2.OptionsColumn.AllowEdit = false;
            this.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] { col1, col2});

            this.Columns["FK_ICDepartmentAttributeValueID"].VisibleIndex = 0;
            this.Columns["ICProductAttributeSerialNo"].VisibleIndex = 1;
            this.Columns["ICInventoryStockQuantity"].VisibleIndex = 2;
            this.Columns["ICInventoryStockSaleOrderQuantity"].VisibleIndex = 3;
            this.Columns["Selected"].VisibleIndex = 4;
        }

        protected override void InitTreeListDataSource()
        {
            ProcessingEntities entity = (ProcessingEntities)((BaseModuleERP)Screen.Module).CurrentModuleEntity;
            this.DataSource = entity.ICProductAttributesList;
        }

        protected void TreeList_CellValueChanging(object sender, DevExpress.XtraTreeList.CellValueChangedEventArgs e)
        {
            
            THSTreeListObject obj = (THSTreeListObject)this.GetDataRecordByNode(this.FocusedNode);
            THSDbUtil.SetPropertyValue(obj, e.Column.FieldName, e.Value);
        }

        protected override String GetLookupTableDisplayColumn(String strLookupTableName)
        {
            
            String strPrimaryColumn = THSDbUtil.GetTablePrimaryColumn(strLookupTableName);
            String displayColumn = strPrimaryColumn.Substring(0, strPrimaryColumn.Length - 2) + "Value";
            return displayColumn;
        }
    }
}
